<template>
  <!-- HTML -->
  <Top-Page>
    <NavBar title="扫一扫" left-arrow @click-left="onClickLeft" />
    <get-qrcode @success="qrcodeSucess" @error="qrcodeError"></get-qrcode>
  </Top-Page>
</template>

<script>
import NavBar from '@/components/NavBar/NavBar.vue';
import scan from '@/common/scan.js';
import getQrcode from '@/components/get-qrcode.vue';
// 嫌路径长的话可以单独复制出来
export default {
  components: {
    getQrcode,
    NavBar
  },
  methods: {
    onClickLeft() {
      uni.navigateBack({
        delta: 1
      });
    },
    qrcodeSucess(data) {
      scan.checkQr(data);
      uni.navigateBack({});
    },
    qrcodeError(err) {
      console.log(err);
      uni.showModal({
        title: '摄像头授权失败',
        content: '摄像头授权失败，请检测当前浏览器是否有摄像头权限。',
        success: () => {
          uni.navigateBack();
        }
      });
    }
  }
};
</script>

<style scoped>
.nav-bar {
  background-color: transparent;
}
</style>
